﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<title>会员储值调整</title>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/find.js"></script>
<!-- InstanceBeginEditable name="EditRegion3" -->
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
<script type="text/javascript">
	/**
	 * 入口，和服务器的通信从此开始
	 */
	$(function() {
		refreshInput($(".serWrapper"));
		initShopSelecter();
		$('.doubledate').kuiDate({
			className : 'doubledate',
			isDisabled : "1" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
		});
		$('.doubledate1').kuiDate({
			className : 'doubledate1',
			isDisabled : "1" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
		});
		$("#depositAdd").hide();
		$(".memberInfo").attr("disabled", "disabled");
		 $('#startDate').val(getToday());
		 $('#endDate').val(getToday());
		 initSelect();
	});
	
	function initSelect(){
		var shopId = $('#shopID').val();
		if(IsEmpty(shopId)){
			$("#shopIsChoosed").removeAttr("checked");
		}
		$('#crMan').val("");
		$('#paid').val();
		$("#memberCardNo").val("")
		$("#mp").val("");
	}
	
	/**
	 * 初始化店面选择器
	 */
	function initShopSelecter() {
		refreshInput($(".serWrapper"));
		$("#shopIsChoosed").removeAttr("checked");
		$("#shopID").attr("disabled", "disabled");

		$("#shopIsChoosed").bind("click", function() {
			var checked = $(this).attr("checked");
			if (checked) {
				$("#shopID").removeAttr("disabled");
			} else {
				$("#shopID").attr("disabled", "disabled");
				$("#shopID").empty();
			}
		});
	}

	
/* 	'../memberDepositBill/find/shopId/' + shopId + '/params/'
	+ (pageIndex - 1) + '/' + _pageSize */

	/**
	 * 为查找做准备，这里主要是生成查询条件对象
	 */
	function toSearch() {
		$("#membersDatail").empty();
		var shopId="";
		if($("#shopIsChoosed").is(":checked")){	
			shopId=getHtmlString($("#shopID").val());
		}
		var startDate = $('#startDate').val();
		var endDate = $('#endDate').val();
		var crMan = $('#crMan').val();
		var paid = $('#paid').val();
		var memberCardNo = $("#memberCardNo").val()
		var mp = $("#mp").val();
		new Pagination({
			url : '../memberDepositBill/find/shopId/2/params/',
			data : {
				shopId : shopId,
				startDate : startDate,
				endDate : endDate,
				crMan : crMan,
				paid : paid,
				memberCardNo : memberCardNo,
				mp:mp
				},
			success : printDataToPage,
			pageSize : 10
		});
		
		var param={'shopId':shopId,'startDate':startDate,'endDate':endDate,'memberCardNo':memberCardNo,'mp':mp,'paid':paid}
		$.ajax({
			type : "get",
			async:false,
			data :param,
			datatype : "json",
			url : "../memberDepositBill/find/memberDepositBillListSum",
			success : function(data) {
				var rst = JSON.parse(data);
							
						var obj = DealAndShowMsg(data,false,false);
						if(rst.state==0){
						if(rst.result.data[0][0]>=0){
						 	$("#sum").html("储值总计："+getHtmlInt(rst.result.data[0][0])+"元    "+"赠送总计："+getHtmlInt(rst.result.data[0][1])+"元"+"  实际总计："+getHtmlInt(rst.result.data[0][2])+"元");	

						}else{
						 	$("#sum").html("");	

						}
							
						}
						
						
			}	
		});
	}
	
	/**
	 * 将数据打印到页面
	 */
	 function printDataToPage(message) {
			dataTable({
				tbodyId : 'membersDatail',
				 heads : ["ShopName", "BillNo", "CreateFileTime", "memberCard", "custName", "mp", "IsDpAdjustment", "Amount","gotDeposit","sum","CreateFileMan","Paid","ID"],
				rst : message,
				sup : {
					id : "sup",
					template : "共 [index] 条"
				},
				handler : [{
					col : 12,
					f : detail
				},{
					col : 11,
					f : paid
				},{
					col : 6,
					f : IsDpAdjustment
				}],
				trGender:trGenders
			});
		}
	
	function IsDpAdjustment(heads, row){
		var storedType = "";
		if(IsNotEmpty(heads)){
			if(heads == 1){
				storedType = "储值变动";
			}else{
				storedType = "会员储值";				
			}
		}else{
			storedType = "会员储值"
		}
		return storedType;
	}
	
	function trGenders(row){
		if(IsNotEmpty(row)){
			return "<tr id='Ids"+row+"' ></tr>";
		}
	}
	
	function paid(heads, row) {
		var paidName = "";
		if(IsNotEmpty(heads)){
			if(heads == 0){
				paidName = "未付";
			}else{
				paidName = "已付";				
			}
		}
		return paidName;
	}
	
	function detail(heads, row) {
		 /* "<input class='common_btn' type='button' value='修改' onclick='toUpdate("+heads+")'><br>"
				+ */
		return	"<input class='del common_btn' type='button' value='删除' onclick='toDelete("+heads+","+row+")'>"+"<input class='stampBtn common_btn' type='button' value='打印' onclick='toPrint("+heads+")'>";
	}
	function toPrint(id){
		window.open('printDepositBill.html?id='+id+"&flag=1")
	}
	/**
	 * 点击充值按钮
	 */
	function toAdd() {

		var shopId =$("#shopID").val()
		if(IsEmpty(shopId)){
			artError("请先选择店铺 ")
			return false
		}else{
			var htm="<option value='"+shopId+"'>"+$("#shopID").text()+"</option>"
			$("#shopID1").html(htm)
		}
	$("#depositAdd").show();
	$("#depositSelect").hide();
	$(".clearValue").val("");
		}
	/**
	 * 返回查询界面按钮
	 */
	function toSelect() {
		$("#depositAdd").hide();
		$("#depositSelect").show();	
	}
	
	/**
	 * 删除一行
	 */
	function toDelete(id,row) {
		if (IsEmpty(id)) {
			artError('未获取到主要信息！');
			return false;
		}
		var paid = $("#Ids"+row).find("td:eq(11)").text();
		if(IsNotEmpty(paid)){
			if(paid == "已付"){
				artError('不能删除已付款的单据');
				return false;
			}
		}
		
		//提示用户 确认删除
		art.dialog({
			'fixed':true,
			'lock':true,
			'title' : '警告',
			'icon':'question',
			'content' : '确定要删除吗？',
			'cancel' : function() {
			},
			'ok' : function() {
				$.post('../memberDepositBill/del', {
					'id' : id
				}, function(message) {
					if (IsEmpty(message)) {
						artError("删除出错");
						return false;
					}
					if (message.state == 0) {
						toSearch();
						artSuccess('删除成功');
					} else if (message.state == 1) {
						artError("删除失败");
					} else {
						checkStateShowErrorMsgAndDealResult(message);
					}
				}, 'json');
			}
		}); 
		//直接发出请求
	}

/* 	function pormptTMessage(idName){
		var message =  "11111";
		$("#"+idName).text("(注："+message+")");
		$("#"+idName).focus();
	} */
	
	
	//付款
	function memberPaid(){
		var shopId = $('#shopID1').val();
		if(IsEmpty(shopId)){
			art.dialog({fixed:true, lock: true,content:"没选择店面",icon:'error',ok:true});	
			return false;
		}
		var amount = $('#Amount').val();
		var memberId = $("#memberId").val();
		if(IsEmpty(memberId)){
			art.dialog({fixed:true, lock: true,content:"会员不能为空",icon:'error',ok:true});	
			return false;
		}
		
		var status = $("#status").val();
		if(status != 2){
			art.dialog({fixed:true, lock: true,content:"会员状态不正常",icon:'error',ok:true});	
			return false;
		}
		
		var reg =/^([0-9]*)|((-?\d+)(\.\d+)?)$/;
		if(IsEmpty(amount)){
			art.dialog({fixed:true, lock: true,content:"储值金额不能为空",icon:'error',ok:true});	
			return false;
		}else if(!(reg.test(amount))){
			art.dialog({fixed:true, lock: true,content:"请输入数字",icon:'error',ok:true});	
			return false;
		}
		
		var memo = $("#Memo").val();
		var status = 0;
		var paid = 1;
		
		var heads = new Array("Amount","memberId","paid","Memo","Status");
		var datas = new Array(amount,memberId,paid,memo,status);
		
		var parser = new Object();
		var jsonParserStr = null;
		if (IsNotEmpty(datas)){
			addToParser(heads, datas, "add" , parser);
			jsonParserStr =  JSON.stringify(parser);
		}
		
		var rst = _PostInfoRst("../memberDepositBill/adjustmentPaid",{"shopId":shopId,"data":jsonParserStr},"付款成功")
		if(IsNotEmpty(rst)){
			var state = rst.state;
			if(state == 0){
				toSelect();
				toSearch();
			}
		}
	}
	
	//查询会员信息
	function selectMemberInfo(){
		var shopId = $('#shopID1').val();
		if(IsEmpty(shopId)){
			art.dialog({fixed:true, lock: true,content:"没选择店面",icon:'error',ok:true});	
			return false;
		}
		var memberCardNo =$("#MemberCardNo").val();
		if(IsEmpty(memberCardNo)){
			art.dialog({fixed:true, lock: true,content:"卡号不能为空",icon:'error',ok:true});	
			return false;
		}
		$.get("../member/find/shopId/"+shopId+"/custInfo/cardNo/"+memberCardNo,{"shopId":shopId},function(data){
			if(IsEmpty(data)){
				art.dialog({fixed:true, lock: true,content:"查询出錯",icon:'error',ok:true});	
				return false;
			}
			memberInfoInit(data);
		},"json")
		
	}
	
	function memberInfoInit(rst){
		//获取行
		var row = rst.result.data.length;
		if(row <= 0){
			return;
		}
		$("#custName").val(getHtmlString(getHeadIndexValue(0,rst,'custName')));
		$("#Mp").val(getHtmlString(getHeadIndexValue(0,rst,'Mp')));
		$("#sex").val(getHtmlString(getHeadIndexValue(0,rst,'sex')));
		$("#Birthday").val(getHtmlString(getHeadIndexValue(0,rst,'Birthday')));
		$("#ValidDateTime").val(getHtmlString(getHeadIndexValue(0,rst,'ValidDateTime')));
		$("#levelName").val(getHtmlString(getHeadIndexValue(0,rst,'levelName')));
		$("#IntegralAmount").val(getHtmlString(getHeadIndexValue(0,rst,'IntegralAmount')));
		$("#CashCouponAmount").val(getHtmlString(getHeadIndexValue(0,rst,'CashCouponAmount')));
		$("#DepositAmount").val(getHtmlString(getHeadIndexValue(0,rst,'DepositAmount')));
		$("#discount").val(getHtmlString(getHeadIndexValue(0,rst,'discount')));
		$("#mStaName").val(getHtmlString(getHeadIndexValue(0,rst,'mStaName')));
		$("#memberId").val(getHtmlString(getHeadIndexValue(0,rst,'ID')));
		$("#status").val(getHtmlString(getHeadIndexValue(0,rst,'status')));
	}
	
</script>
</head>
<body>
	<!-- 页面列表 -->
	<div class="container" id="container">
		<div class="container_R fr" id="depositSelect">
			<div class="place">会员储值调整</div>
			<div class="member_search">
				<p>
					<span> <input type="checkbox" id="shopIsChoosed"
						style="width: auto; height: auto; border: none;"> 店面：
					</span><select id="shopID"  class="shopName" onclick="openShopListPanel(this)" style="height: 20px;"></select>
					</select> <span>起始日期：</span> <input type="text" readonly
						class="doubledate ipticon" id="startDate" /> <span>截止日期：</span> <input
						type="text" readonly class="doubledate1 ipticon" id="endDate" />
				</p>
				<p>
					<span>会员卡号：</span> <input type="text" id="memberCardNo" class="absoluteTxt" />
					<span>手机：</span> <input type="text" id="mp" class="absoluteTxt"/> 
					<span>支付状态：</span><select
						id="paid" class="status">
						<option value="">所有</option>
						<option value="0">未付</option>
						<option value="1">已付</option>
					</select> <input type="button" value="查询" class="btn" onclick="toSearch()">
				</p>
				<!-- 					<span>单据状态：</span> <select id="status">
						<option value="">所有</option>
						<option value="0">未审</option>
						<option value="1">已审</option>
					</select>  -->

			</div>
			<table width="100%" class="member_list" cellpadding="0"
				cellspacing="1" border="0" id="memberList">
				<caption>
					<strong>储值详情列表 <span  id="sup">共0条</span></strong><input
						type="button" class="common_btn" value="储值调整" id="addColumn" onclick="toAdd()">
				</caption>
				<thead>
					<tr>
						<th>店面</th>
						<th >单据号</th>
						<th >办理时间</th>
						<th >会员卡号</th>
						<th >会员姓名</th>
						<th >电话</th>
						<th >储值类型</th>
						<th >储值金额</th>
						<th >赠送金额</th>
						<th >实际金额</th>
						<th>经办人</th>
						<th >支付状态</th>
						<th >操作</th>
					</tr>
				</thead>
				<tbody id="membersDatail">

				</tbody>
			</table>
    <div id="sum" style="float: left;"></div>
			<div id="pager" style="float: right;"></div>
		</div>
		<input type="hidden" id="billId">
		<div class="container_R fr" style="padding: 17px; width: 773px;" id="depositAdd">
		      <div class="place"><a onclick="toSelect()">储值调整</a><span> &gt;</span> <span>储值调整</span><a class="goHome" style="cursor: pointer;" onclick="toSelect()">返回</a></div>
			  <div class="member_search">
			  	<form id="manForm">
				  	<p><label><span>店面：</span><select id="shopID1" class="shopName" class="clearValue" onclick="openShopListPanel(this)" style="height: 20px;"></select></label>
			  		<label><span>会员卡号：</span><input id="MemberCardNo" class="clearValue" onkeypress="if(event.keyCode==13){selectMemberInfo()}" type="text"/><input type="button"  class="btn common_btn" value="查询" onclick="selectMemberInfo()" /></label></p>
				  	<p><label><span>姓名：</span><input id="custName" class="memberInfo clearValue" type="text"/></label><label><span>手机号：</span><input id="Mp" class="memberInfo clearValue" type="text"/></label><label><span>性别：</span><input id="sex" class="memberInfo clearValue" type="text"/></label></p>
			  		<p><label><span>生日：</span><input id="Birthday" class="memberInfo clearValue" type="text"/></label><label><span>卡失效日期：</span><input id="ValidDateTime" class="memberInfo clearValue" type="text"/></label><label><span>会员级别：</span><input id="levelName" class="memberInfo clearValue" type="text"/></label></p>
			  		<p><label><span>积分：</span><input id="IntegralAmount"  class="memberInfo clearValue" type="text"/></label><label><span>代金券(元)：</span><input id="CashCouponAmount" class="memberInfo clearValue" type="text"/></label><label><span>储值(元)：</span><input id="DepositAmount" class="memberInfo clearValue" type="text"/></label></p>
			  		<p><label><span>折扣：</span><input id="discount" class="memberInfo clearValue" type="text"/></label><label><span>卡状态：</span><input id="mStaName" class="memberInfo clearValue" type="text"/></label><input type="hidden" class="memberInfo clearValue" id="memberId"><input type="hidden" class="memberInfo clearValue" id="status"></p>
				  	<p><label><span>储值调整金额：</span><input type="text" id="Amount" class="clearValue" ></label></p>
				  	<p><label><span>备注：</span><textarea id="Memo" class="clearValue" style="width: 500px;"></textarea></label></p>
				</form>
				<div class="BottomBtn" >
					<input id="paid_btn" class="check_btn" value="付款" type="button"  onclick="memberPaid()">
				</div>
			 </div>
		</div>
		
					<!-- 会员储值规则 
			<div class="hideDiv hideOver" id="window2">
			 <div class="closeTop"><span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span></div>
				<table id="storedRules" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
			    	<caption>会员储值规则列表</caption>
			    	<thead>
				    	<tr>
				        	<th>店名称</th>
				        	<th>储值规则名称</th>
				        	<th>生效日期</th>
				        	<th>失效日期</th>
				        	<th>状态</th>
				        </tr>
			        </thead>
			        <tbody id="tStoredRule">
			        </tbody>
			    </table>
 				<div id="storeRPager" class="pager"></div>
 				
			    <table id="storedRulesDt" width="100%" cellspacing="1" cellpadding="0" border="0" class="member_list">
			    	<caption>会员储值规则列表</caption>
			    	<thead>
				    	<tr>
				        	<th>储值金额</th>
				        	<th>赠送金额</th>
				        	<th>实际金额</th>
				        	<th>享受折扣</th>
				        	<th>操作</th>
				        </tr>
			        </thead>
			        <tbody id="tStoredRuleDt">
			        </tbody>
			    </table>
 				<div id="storeRDtPager" class="pager"></div>
			</div>-->
		
<!-- 		<div class="container_R fr" style="padding: 17px; width: 773px;" id="depositEdit">
		      <div class="place"><a onclick="toSelect()">会员储值</a><span> &gt;</span> <span>储值修改</span><a class="goHome" onclick="toSelect()">返回</a></div>
				<div class="member_search">
			  	<form id="manForm1">
			  		<p><label><span>会员卡号：</span><input id="MemberCardNo1"  type="text"/><input type="button"  class="check_btn" value="查询" /></label></p>
			  		<p><label><span>姓名：</span><input id="custName1" class="memberInfo" type="text"/></label><label><span>手机号：</span><input id="Mp1" class="memberInfo" type="text"/></label><label><span>性别：</span><input id="sex1" class="memberInfo" type="text"/></label></p>
			  		<p><label><span>生日：</span><input id="Birthday1" class="memberInfo" type="text"/></label><label><span>卡失效日期：</span><input id="ValidDateTime1" class="memberInfo" type="text"/></label><label><span>会员级别：</span><input id="levelName1" class="memberInfo" type="text"/></label></p>
			  		<p><label><span>积分：</span><input id="IntegralAmount1"  class="memberInfo" type="text"/></label><label><span>代金券(元)：</span><input id="CashCouponAmount1" class="memberInfo" type="text"/></label><label><span>储值(元)：</span><input id="DepositAmount1" class="memberInfo" type="text"/></label></p>
			  		<p><label><span>折扣：</span><input id="discount1" class="memberInfo" type="text"/></label><label><span>卡状态：</span><input id="mStaName1" class="memberInfo" type="text"/></label><input type="hidden" class="memberInfo" id="memberId1"><input type="hidden" class="memberInfo" id="status1"></p>
			  		<br><br><br><br>
			  		<p><label><span>店面：</span><select id="shopID12" class="shopName"  onclick="openShopListPanel(this)" style="height: 20px;"></select></label><label><span>单据号：</span><input type="text" id="BillNo1"  onfocus="pormptMessage('填写单号后系统将不自动生成单号','nots')"  onblur="focusFail('nots')"></label><em id="nots1" style="color: red;"></em></p>
				  	<p><label><span>享受储值：</span><select id="storedRule1" class="shopName"  onclick="selectStoredRule(this)" style="height: 20px;"></select></label><label><span>赠送金额：</span><input disabled="disabled"  id="gotDeposit1" type="text" /></label></p>
				  	<p><label><span>储值金额：</span><input type="text" id="Amount1"  onblur="focusFail('ts')"></label><em id="ts1" style="color: red;"></em></p>
				  	<p><label><span>备注：</span><textarea id="Memo1" style="width: 500px;"></textarea></label></p>
				</form>
				<div class="BottomBtn" >
					<input id="save_btn1" class="check_btn" value="修改" type="button"  onclick="memberDpUpdateSave()">			
					<input id="paid_btn1" class="check_btn" value="付款" type="button"  onclick="memberPaid()">
				</div>
			 </div>
		 
		</div>-->
		<div class="fc"></div>
	</div>

	<!-- InstanceEndEditable -->
	<script type="text/javascript" src="../js/header.js"></script>
	<script type="text/javascript" src="../js/left.js"></script>
	<script type="text/javascript" src="../js/footer.js"></script>
	<script type="text/javascript">
	clearThis("absoluteTxt");
	</script>
</body>
<!-- InstanceEnd -->
</html>
